package cn.com.xy.sms.sdk.ui.popu.part;

import java.util.Map;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import cn.com.xy.sms.sdk.Iservice.XyCallBack;
import cn.com.xy.sms.sdk.constant.Constant;
import cn.com.xy.sms.sdk.smsmessage.BusinessSmsMessage;
import cn.com.xy.sms.sdk.ui.R;
import cn.com.xy.sms.sdk.ui.popu.part.UIPart;
import cn.com.xy.sms.sdk.ui.popu.util.ChannelContentUtil;
import cn.com.xy.sms.sdk.ui.popu.util.ThemeUtil;
import cn.com.xy.sms.sdk.util.StringUtils;

public class BubbleVerificationTextBody extends UIPart {

    private TextView mVeriTitleTv;
    private TextView mVeriContTv;
    private View mVeriSplite;
    private TextView mVeriHintTv;

    public BubbleVerificationTextBody(Activity context, BusinessSmsMessage message, XyCallBack callback, int layoutId,
            ViewGroup root, int partId) {
        super(context, message, callback, layoutId, root, partId);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void initUi() throws Exception {
        // TODO Auto-generated method stub
        super.initUi();
        mVeriTitleTv = (TextView) mView.findViewById(R.id.duoqu_sms_verification_title);
        mVeriContTv = (TextView) mView.findViewById(R.id.duoqu_sms_verification_content);
        mVeriSplite = mView.findViewById(R.id.duoqu_sms_verification_splite_view);
        mVeriHintTv = (TextView) mView.findViewById(R.id.duoqu_sms_verification_hint);
    }

    @SuppressLint("ResourceAsColor")
    @Override
    public void setContent(BusinessSmsMessage message, boolean isRebind) throws Exception {
        // TODO Auto-generated method stub
        super.setContent(message, isRebind);
        setViewStyle(message);
        
        String veriTitle = (String) message.getValue("m_by_text_u_1");
        String veriCont = (String) message.getValue("m_by_text_d_1");
        String veriHint = (String) message.getMessageBody();
        /* SMARTISAN-280 zhaoxiachao 20161202 start */
        String flag=(String) mMessage.getValue("mark");
        if(StringUtils.isNull(flag)){
            mVeriContTv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, ChannelContentUtil.needUpdateContTextSize(veriCont));
        }else {
            mVeriContTv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, ChannelContentUtil.needEnglishUpdateTextSize(veriCont));
        }
        /* SMARTISAN-280 zhaoxiachao 20161202 end */
        
        
        ChannelContentUtil.setText(mVeriTitleTv, veriTitle, "");
        ChannelContentUtil.setText(mVeriContTv, veriCont, "");
        ChannelContentUtil.setText(mVeriHintTv, veriHint, message.getMessageBody());

        /* SMARTISAN-284 zhaoxiachao 20161202 start */
        if(veriCont.contains("\n")){
            mVeriContTv.setGravity(Gravity.CENTER);
        }else{
            mVeriContTv.setGravity(Gravity.CENTER_VERTICAL);
        }
        /* SMARTISAN-284 zhaoxiachao 20161202 end */
        if(!StringUtils.isNull(veriCont)){
            mVeriSplite.setVisibility(View.VISIBLE);
        }else{
            mVeriSplite.setVisibility(View.GONE);
        }
        
        if (StringUtils.isNull(veriHint)) {
            mVeriHintTv.setVisibility(View.GONE);
        } else {
            mVeriHintTv.setVisibility(View.VISIBLE);
        }
        
    }

    @SuppressLint("ResourceAsColor")
    private void setViewStyle(BusinessSmsMessage message) {
        ThemeUtil.setViewBg(Constant.getContext(), mView, "", R.drawable.duoqu_v_by_bg_1);
        ThemeUtil.setViewBg(Constant.getContext(), mVeriSplite, message.getImgNameByKey("v_by_line_1"),
                R.color.duoqu_theme_color_5011);

        ThemeUtil.setTextColor(mContext, mVeriTitleTv, (String) message.getValue("v_by_text_u_1"),
                R.color.duoqu_theme_color_5010);
        ThemeUtil.setTextColor(mContext, mVeriContTv, (String) message.getValue("v_by_text_d_1"),
                R.color.duoqu_theme_color_3010);
        ThemeUtil.setTextColor(mContext, mVeriHintTv, (String) message.getValue("v_by_original"), R.color.duoqu_theme_color_5010);
    }

    @Override
    public void changeData(Map<String, Object> param) {
        /* SMARTISAN-261 zhaoxiachao 20161129 start */
        if(param != null && !StringUtils.isNull(param.get(ChannelContentUtil.CHANGE_TRAIN)+"")){
            return;
        }
        /* SMARTISAN-261 zhaoxiachao 20161129 end */
    }
}
